<?php
        
        class PViewManager
        {
       		var $puzzle;
       		
       		var $execution;
       		
       		var $next_id;
       		
       		
       		function PViewManager(&$owner)
       		{
       			$this->puzzle = $owner;
       		}
        	
                function createView($view, $extension = null)
                {
                	if ($extension == null)
                	{
                		$extension = $this->puzzle->PEM->current_extension;
                	}
                	
                	if ($this->puzzle->PEM->existExtension($extension))
                	{
                		if ($this->existView($view, $extension))
                		{
                			$v = new PView($this->puzzle, $extension, $view);
					return $v;
				}
				else
				{
					die("Puzzle :: Error :: View $view in extension $extension does not exist");
				}
			}
			else
			{
				die("Puzzle :: Error :: Loading view $view :: Extension $extension does not exist");
			}
                }
                
                function loadView($view, $extension = null)
                {
                	$v = $this->createView($view, $extension);
                        $v->initialize();
                        return $v;
                }
                
                function showView($view, $extension = null)
                {
                        $v = $this->loadView($view, $extension);
                        
                        $v->render();
                        
                        return $v;
                }
                
                function existView($view, $extension = null)
                {
                	$DS = $this->puzzle->config['DS'];
                	
			if ($extension == null)
			{
				$extension = $this->puzzle->PEM->current_extension;
			}

			if ($this->puzzle->PEM->existExtension($extension))
			{

				if (file_exists($this->puzzle->config['dir_ext'] . $DS . $extension . $DS .  $this->puzzle->config['dir_ext_src'] . $DS . $this->puzzle->config['dir_ext_views'] . $DS . $view))
				{
					return true;
				}
				else
				{
					return false;
				}
			}
			else
			{
				return false;
			}
                }
                
                function nextID()
                {
                	$this->next_id++;
                	return $this->next_id;
                }
        }
        
?>
